<?php
session_start();
    
    // Created By : Julian Ponce
    // B.S. Computer Science - De La Salle Canlubang
    // November 28, 2011
    // IN PARAMETERS : accountUserId, action
    // 
    // This AJAX Request sets an account status to be "Active" or "Inactive" 
    // based on passed parameter "action".


if ($_POST) {
    include('../includes/siteConfig.php');
    
    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');

    // GET VARIABLES VIA POST METHOD
    $accountUserId = $_POST['accountUserId'];
    $action = $_POST['action'];
     
    //GET THE CURRENT DATE TIME
    date_default_timezone_set('Asia/Singapore');
    $currentDateTime= date("Y-m-d H:i:s" , time());
    
    //IF ACTION IS "Deactivate" Query = Deactivate
    if ($action == "Deactivate") {    
        $query = 
        "
            UPDATE Account
            SET status = 'Inactive', accountLastUpdated = '$currentDateTime'
            WHERE userId = '$accountUserId'
        ";
    }
    
    // ELSE, ACTIVATE ACCOUNT
    else {
        $query = 
        "
            UPDATE Account
            SET status = 'Active', accountLastUpdated = '$currentDateTime'
            WHERE userId = '$accountUserId'
        ";
    }
        
    mysql_query($query);
    
    echo json_encode(1);
   
    mysql_close($connect);
}   // End - Checker for those users who will just go to the page by typing directly in the url.
else {
 echo "You are not authorized to view this page. This incident will be reported immediately.";
}
?>
